<template>
    <div>
        <div class="risk-box-div">
            <div class="risk-box-title">{{businessType == 'businesstype_control' ? '管控措施' : '作业风险'}}</div>
            <ul class="risk-ul">
                <li class="risk-li" v-for="(item,index) in checkedRows" :key="index">
                    <span class="xuhao">{{index + 1}}</span>
                    <span class="risk-name" v-if="businessType == 'businesstype_control'">{{item.measures}}</span>
                    <span class="risk-name" v-else>{{item.riskName ? item.riskName : item.riskOperationName}}</span>
                </li>
            </ul>
            <div class="risk-box-title" style="padding-bottom:0;">问询</div>
            <div class="risk-box-title" style="color:#677897;font-size:12px;padding-bottom:5px;">*问询内容</div>
            <Input v-model="questionText" type="textarea" :rows="4" placeholder="请输入问询内容" maxlength="500" @input="descInput" show-word-limit />
            <div class="risk-box-title" style="color:#677897;font-size:12px;padding-bottom:5px;padding-top:5px;">*问询对象</div>
            <div class="pople-xz">
                <Input v-model="people" placeholder="请选择问询对象" readonly style="width: 300px" />
                <Button type="primary" style="margin-left:20px;" @click="checkPerson">选择</Button>
            </div>
        </div>
        <div class="buttom-footer">
            <button type="button" class="ivu-btn ivu-btn-text" @click="$emit('modelBox',false)">
                取消
            </button>
            <button type="button" class="ivu-btn ivu-btn-primary" @click="inquiries()">
                提交
            </button>
        </div>
    </div>
</template>
<script>
import Utils from '../../../common/util'
export default {
    props:['checkedRows','businessType'],
    data(){
        return{
            questionText:'',
            people:'',
            peopleIds:[],
            peopleArr:[]
        }
    },
    mounted(){
        let self = this
        // 接收选择的人员
        Utils.$on('checkPersons',(msg)=>{
            // self.peopleArr = msg
            self.peopleIds = []
            let arr = []
            msg.forEach(e => {
                arr.push(e.name)
                self.peopleIds.push(e.personUserOrgId)
            })
            self.people = arr.join('、')
        })
    },
    methods:{
        // 判断选择的风险数量和是不是同一个风险
        isModel(){
            this.questionText = ''
            this.people = ''
            this.peopleIds = []
            this.isInquiries = true
        },
        descInput(){},
        checkPerson(){
            if(this.people == '' || this.people == undefined){
                this.peopleArr = []
            }
            this.$emit('person',true)
            Utils.$emit('personCheck',this.peopleArr)
        },
        // 问询提交
        inquiries(){
            if(!this.questionText){
                this.$Message.warning('问询内容不能为空')
                return false
            }else if(!this.people){
                this.$Message.warning('问询对象不能为空')
                return false
            }
            let parmes = {
                businessType:this.businessType,
                objectIds:[],
                questionText:this.questionText,
                answerUserIds:this.peopleIds
            }
            this.checkedRows.forEach(e=>{
                parmes.objectIds.push(e.id ? e.id : e.riskOrderId)
            })
            this.$api.messageManage.questionAdd(parmes).then(resp=>{
                if(resp.code == 200){
                    this.$Message.success('添加成功')
                    this.$emit('modelBox',false)
                }
            })
        }
    }
}
</script>
<style lang="scss" scoped>
 .risk-box-div{
    .risk-box-title{
        height: 20px;
        font-size:14px;
        font-family:PingFangSC-Medium,PingFang SC;
        font-weight:500;
        color:rgba(51,51,51,1);
        line-height:20px;
        padding-bottom: 10px;
        display: table;
        font-weight: bold;
    }
    .risk-ul{
        background:rgba(255,255,255,1);
        border:1px solid rgba(214,221,229,1);
        margin-bottom: 10px;
        .risk-li:first-child{
            border:none;
        }
        .risk-li{
            list-style: none;
            height: 40px;
            line-height: 40px;
            width: 100%;
            border-top:1px solid rgba(214,221,229,1);
            .xuhao{
                width: 10%;
                display: block;
                text-align: center;
                float: left;
            }
            .risk-name{
                width: 90%;
                display: block;
                text-align: center;
                font-size:13px;
                font-family:PingFangSC-Regular,PingFang SC;
                font-weight:400;
                color:rgba(98,113,129,1);
                float: left;
            }
        }
    }
 }
.buttom-footer{
    margin-top: 20px;
    padding: 12px 0 0 18px;
    border-top:1px solid #e8eaec;
    text-align: right;
}
</style>